package p.ithorns.integration.hazelcast.mqtt;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * CardMsg
 * -Tag_MAC(4)
 * -Version(2)
 * -RSSI(2)
 * -Snr(1)
 * -AlarmFlags(1)
 * -Voltage(1)
 * -BMA_Value(1)
 * -RawDatas(n)
 *
 * @author liuhaitao
 * @version 1.0
 * @date 2022/3/12 14:25
 */
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CardRaw implements Serializable {

    /**
     * 标签卡编号
     * 工牌蓝牙MAC地址低4字节
     */
    private String cardCode;

    /**
     * 网关编号
     */
    private String gateCode;

    /**
     * Lora网关接收工牌信号时的RSSI值
     * 2字节
     */
    private int rssi;

    /**
     * 时间戳
     * (设备上报)
     */
    private long timestamp;

    /**
     * 活跃(解算)时间
     */
    private long activeTime;

    /**
     * 1秒内计步步数
     */
    private Integer step;

    /**
     * 工牌电压，单位为20mV
     * 1字节
     */
    private Double voltage;

    /**
     * 休眠状态
     */
    private Boolean sleep;

    /**
     * SOS
     */
    private Boolean sos;

    /**
     * 是否活动的
     */
    private boolean active;

    /**
     * Beacon源数据列表
     */
    private List<BeaconRaw> beaconRaws;


    @Override
    public String toString() {
        return "{" +
                "cardCode:'" + cardCode + '\'' +
                ", rssi:" + rssi +
                ", timestamp:" + timestamp +
                ", sos:" + sos +
                ", sleep:" + sleep +
                ", step:" + step +
                ", voltage:" + voltage +
                ", beaconRaws:" + beaconRaws +
                "}";
    }

    /**
     * 休眠状态
     * 0-运动；1-休眠
     *
     * @return int
     */
    @JsonIgnore
    public int getSleepStatus() {
        return Optional.ofNullable(sleep).orElse(false) ? 1 : 0;
    }

    /**
     * sos状态
     * 0-未报警；1-报警
     *
     * @return int
     */
    @JsonIgnore
    public int getSosStatus() {
        return Optional.ofNullable(sos).orElse(false) ? 1 : 0;
    }

}
